package ru.papergames.web.services.users;

import org.hibernate.Query;
import org.hibernate.Session;
import ru.common.hibernate.HibernateAction;
import ru.papergames.common.form.PcPlayerForm;
import ru.papergames.common.model.PcPlayer;
import ru.papergames.web.forms.UserForm;
import ru.papergames.web.model.User;

import java.util.List;

/**
 * @author Alexander Troshanin
 */
public class LogonPcPlayer implements HibernateAction<PcPlayerForm>{

    private final String username;
    private final String password;

    public LogonPcPlayer(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public PcPlayerForm execute(Session session) {
        Query q = session.createQuery("select x from PcPlayer x where x.username=:username and x.password=:password");

        q.setString("username", username);
        q.setString("password", password);

        List<PcPlayer> lst = q.list();
        return lst!=null && lst.size() >0 ? new PcPlayerForm(lst.get(0)) : null;
    }
}
